<?php

define("TOKEN", "pinpinwang");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->valid();

class wechatCallbackapiTest
{
	public function valid()
	{
		$signature = $_GET["signature"];
		$timestamp = $_GET["timestamp"];
		$nonce = $_GET["nonce"];
		$token = TOKEN;
		$tmpArr = array($token, $timestamp, $nonce);
		sort($tmpArr, SORT_STRING);
		$tmpStr = implode( $tmpArr );
		$tmpStr = sha1( $tmpStr );
		if( $tmpStr == $signature ){
			die($_GET["echostr"]);
		}else{
			return false;
		}
	}
}



// $post = $GLOBALS['HTTP_RAW_POST_DATA'];
// $message = simplexml_load_string( $post, 'SimpleXMLElement', LIBXML_NOCDATA );
// $time=time();

// echo <<<str
// <xml>
// <ToUserName><![CDATA[{$message->FromUserName}]]></ToUserName>
// <FromUserName><![CDATA[{$message->ToUserName}]]></FromUserName>
// <CreateTime>{$time}</CreateTime>
// <MsgType><![CDATA[text]]></MsgType>
// <Content><![CDATA[test成功]]></Content>
// </xml>
// str;

?>